package com.testDemo.enrty;

import java.util.ArrayList;
import java.util.List;

import com.testDemo.utils.TestUtils;

/**
 * 每个元素的实体
 * @author Administrator
 */
public class Element {

    private String elementName;
    private String fatherNodeName;
    private String checkType;
    private String elementType;
    private String explan;
    private List<Element> childElements = new ArrayList<Element>();
    private String htmlContent; // 该节点的html格式
    private boolean isFatherNode = false;// 默认不是父节点
    private int classLevel = 0; // 默认的div等级0-代表是msg节点或是子元素
    private Object value = "";
    private boolean isSelection = false;// 是否为选择框,false-为输入框,true-单选框
    private List<String> options = null;// 放单选框的值,格式: value-explan

    private static String selectionRex = "\n";// 判断是否为选择框的正则表达式

    public Element() {

    }

    public Element(String elementName, String fatherNodeName, String checkType, String elementType, String explan,
            List<Element> childElements, Object value) {
        super();
        this.elementName = elementName;
        this.fatherNodeName = fatherNodeName;
        this.checkType = checkType;
        this.elementType = elementType;
        this.explan = explan;
        if (!TestUtils.isEmpty(childElements)) {
            this.childElements = childElements;
        }
        if (!TestUtils.isEmpty(value)) {
            this.value = value;
        }
        /**
         * 判断该节点是否为选择框,判定规则:有说明存在,并且其中含有[回车]以及[-]键,会根据[-]键分割选择框的key和value
         */
        if (!TestUtils.isEmpty(explan) && explan.contains(selectionRex) && explan.contains("-")) {
            isSelection = true;
            options = new ArrayList<String>();
            String selecttionContent = explan.substring(explan.indexOf("：") + 1);
            String[] options = selecttionContent.split(selectionRex);
            for (String option : options) {
                if (!TestUtils.isEmpty(option)) {
                    this.options.add(option);
                }
            }
            // 非必传的选择框设置首位值为空
            if (!TestUtils.isEmpty(this.options) && "N".contains(this.checkType)) {
                List<String> allOptions = new ArrayList<String>();
                allOptions.add("-__请选择__");
                allOptions.addAll(this.options);
                this.options = allOptions;
            }
        }
    }

    public int getClassLevel() {
        return classLevel;
    }

    public void setClassLevel(int classLevel) {
        this.classLevel = classLevel;
    }

    public Object getValue() {
        return value;
    }

    public void setValue(Object value) {
        this.value = value;
    }

    public boolean isFatherNode() {
        return isFatherNode;
    }

    public void setFatherNode(boolean isFatherNode) {
        this.isFatherNode = isFatherNode;
    }

    public String getHtmlContent() {
        return htmlContent;
    }

    public void setHtmlContent(String htmlContent) {
        this.htmlContent = htmlContent;
    }

    public String getElementName() {
        return elementName;
    }

    public void setElementName(String elementName) {
        this.elementName = elementName;
    }

    public String getFatherNodeName() {
        return fatherNodeName;
    }

    public void setFatherNodeName(String fatherNodeName) {
        this.fatherNodeName = fatherNodeName;
    }

    /**
     * 是否必选标识 Y,N,*,+
     */
    public String getCheckType() {
        return checkType;
    }

    /**
     * 是否必选标识 Y,N,*,+
     */
    public void setCheckType(String checkType) {
        this.checkType = checkType;
    }

    public String getElementType() {
        return elementType;
    }

    public void setElementType(String elementType) {
        this.elementType = elementType;
    }

    public String getExplan() {
        return explan;
    }

    public void setExplan(String explan) {
        this.explan = explan;
    }

    public List<Element> getChildElements() {
        return childElements;
    }

    public void setChildElements(List<Element> childElements) {
        this.childElements = childElements;
    }

    public boolean isSelection() {
        return isSelection;
    }

    public void setSelection(boolean isSelection) {
        this.isSelection = isSelection;
    }

    public List<String> getOptions() {
        return options;
    }

    public void setOptions(List<String> options) {
        this.options = options;
    }

    @Override
    public String toString() {
        return "Element [elementName=" + elementName + ", fatherNodeName=" + fatherNodeName + ", checkType="
                + checkType + ", elementType=" + elementType + ", explan=" + explan + ", childElements="
                + childElements + ", htmlContent=" + htmlContent + ", isFatherNode=" + isFatherNode + ", classLevel="
                + classLevel + ", value=" + value + ", isSelection=" + isSelection + ", options=" + options + "]";
    }

}
